package org.dromara.common.core.exception;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;

/**
 * 业务异常
 * <p>
 * blog:  code:
 */
public class BusinessException extends RuntimeException {

    private static final long serialVersionUID = 6610083281801529147L;

    public BusinessException(String message) {
        super(message);
    }


    public static void isNull(Object obj, String message) {
        if (ObjectUtil.isNull(obj)) {
            throw new BusinessException(message);
        }
    }

    /**
     * 非空 异常
     *
     * @param obj
     * @return void
     * @author 王星
     * @date 2024-03-13 15:54:49
     */
    public static void notNull(Object obj, String message) {
        if (ObjectUtil.isNotNull(obj)) {
            throw new BusinessException(message);
        }
    }

    /**
     * 集合空 异常
     *
     * @param obj
     * @return void
     * @author 王星
     * @date 2024-03-13 15:57:06
     */
    public static void isEmpty(Object obj, String message) {
        if (ObjectUtil.isEmpty(obj)) {
            throw new BusinessException(message);
        }
    }

    /**
     * 集合非空 异常
     *
     * @param obj
     * @return void
     * @author 王星
     * @date 2024-03-13 15:57:10
     */
    public static void notEmpty(Object obj, String message) {
        if (ObjectUtil.isNotEmpty(obj)) {
            throw new BusinessException(message);
        }
    }

    /**
     * true异常
     *
     * @param obj
     * @param message
     * @return void
     * @author 王星
     * @date 2024-05-21 16:41:38
     */
    public static void isTrue(Boolean obj, String message) {
        if (BooleanUtil.isTrue(obj)) {
            throw new BusinessException(message);
        }
    }

    /**
     * false异常
     *
     * @param obj
     * @param message
     * @return void
     * @author 王星
     * @date 2024-05-21 16:41:38
     */
    public static void isFalse(Boolean obj, String message) {
        if (BooleanUtil.isFalse(obj)) {
            throw new BusinessException(message);
        }
    }
}
